package com.ihisun.tmhcms.controller.doctorcontroller;

import com.ihisun.tmhcms.core.dao.doctordao.DoctorDao;
import com.ihisun.tmhcms.core.dto.doctordto.EditDoctorDto;
import com.ihisun.tmhcms.core.dto.doctordto.SearchDoctorDto;
import com.ihisun.tmhcms.core.service.doctorservice.DoctorService;
import com.ihisun.tmhcms.core.service.doctorservice.EditDoctorService;
import com.ihisun.tmhcms.core.vo.DoctorVo;
import com.ihisun.tmhcms.core.vo.MechanismVo;
import com.ihisun.tmhcms.core.vo.ProjectClassVo;
import com.ihisun.tmhcms.utils.ResponseVo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "医生相关Api")
@RequestMapping("/doctor")
@RestController
public class DoctorController {
    @Resource
    EditDoctorService editDoctorService;
    @Resource
    DoctorService doctorService;
    @Resource
    DoctorDao doctorDao;

    @PostMapping("/editDoctor")
    @ApiOperation(value = "编辑医生", response = EditDoctorDto.class)
    public ResponseVo EditDoctor(@RequestBody EditDoctorDto editDoctorDto) {
        return editDoctorService.editDoctor(editDoctorDto);
    }


    @GetMapping("/findByDoctorInfo")
    @ApiOperation(value = "医生详情", response = DoctorVo.class)
    @ApiImplicitParam(name = "doctorId", value = "医生id", dataType = "String", paramType = "query")
    public ResponseVo doctorInfo(String doctorId) {
        return doctorService.findByDoctorInfo(doctorId);
    }

    @GetMapping("/findByMyMechanism")
    @ApiOperation(value = "查新已经绑定的机构", response = MechanismVo.class)
    public ResponseVo findByMyMechanism(@RequestParam(required = false) @ApiParam(name = "doctorId", value = "医生id") String doctorId) {
        return doctorService.findByDoctorMechanism(doctorId);
    }

    @GetMapping("/findByNotBangdinMechanism")
    @ApiOperation(value = "查询没有绑定的机构", response = MechanismVo.class)
    public ResponseVo findByNotBangdinMechanism(@RequestParam(required = false) @ApiParam(name = "doctorId", value = "医生id") String doctorId) {
        ResponseVo byState = doctorService.findByState(doctorId, 1);
        return byState;
    }

    @GetMapping("/updateDoctorState")
    @ApiOperation("修改医生状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctorId", value = "机构id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "stateValue", value = "状态值  1正常  2冻结  3删除", dataType = "String", paramType = "query")
    })
    public ResponseVo updateDoctorState(String doctorId, String stateValue) {
        DoctorVo doctorVo = doctorService.updateDoctorState(doctorId);
        doctorVo.setState(Integer.parseInt(stateValue));
        doctorDao.save(doctorVo);
        return ResponseVo.ok();
    }


    @GetMapping("/updateDoctorRecommend")
    @ApiOperation("推荐状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctorId", value = "机构id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "stateValue", value = "状态值  1推荐  2非推荐", dataType = "String", paramType = "query")
    })
    public ResponseVo updateDoctorRecommend(String doctorId, String stateValue) {
        DoctorVo doctorVo = doctorService.updateDoctorState(doctorId);
        doctorVo.setRecommend(Integer.parseInt(stateValue));
        doctorDao.save(doctorVo);
        return ResponseVo.ok();
    }



    @PostMapping("/searchDoctor")
    @ApiOperation(value="搜索医生",response = SearchDoctorDto.class)
    public ResponseVo searchDoctor(@RequestBody SearchDoctorDto searchDoctorDto){
        return doctorService.searchDoctor(searchDoctorDto);
    }


    @GetMapping("/findByProjectClassName")
    @ApiOperation(value = "回显项目分类",response = ProjectClassVo.class)
    public ResponseVo findByProjectClassName(){
        return doctorService.findeByProjectClassName();
    }


}
